package com.example.entity;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.example.utils.GetUUID;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

import java.io.*;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author:0xOO
 * @Date: 2018/9/26 0026
 * @Time: 14:39
 */
@Data
@Accessors(chain = true) //开启链式调用 eg: user.setA().setB()
public class User {
    final static Map<String,JSONArray> cacheEmoji = new HashMap<>(1000000);
    private Integer id;
    private String userName;
    private String passWord;
    private String realName;
    private String displayName;
    private String url;
    public User(){}
    public User(String userName,String passWord,String realName,String displayName,String url){
        this.userName = userName;
        this.passWord = passWord;
        this.realName = realName;
        this.displayName = displayName;
        this.url = url;

    }
    public static List<User> getListUser(){
        Long start =  System.nanoTime();
        List<User> listUser = new ArrayList<>(100000);
        for (int i = 0; i < 100000; i++) {
                StringBuilder stringBuilder = new StringBuilder();
                JSONObject jsonObject =  JSON.parseObject(getEmoji());
                stringBuilder.append("user");
                stringBuilder.append(System.nanoTime());
                String passWord = System.nanoTime()+"";
                String realName = System.nanoTime()+"";
                String displayName = (String) jsonObject.get("display_name");
                String url =  (String) jsonObject.get("url");
                User user = new  User(stringBuilder.toString(),passWord,realName,displayName,url);
                listUser.add(user);
        }
        System.out.println("批量生成数据耗时："+(System.nanoTime()-start));
        return listUser;
    }
    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", userName='" + userName + '\'' +
                ", passWord='" + passWord + '\'' +
                ", realName='" + realName + '\'' +
                ", displayName='" + displayName + '\'' +
                ", url='" + url + '\'' +
                '}';
    }

    public static String getEmoji(){
        int radIdx = RandomUtils.nextInt(0, 218);
        String result = JSON.toJSONString(reader().get(radIdx));
        return result;
    }
    public static JSONArray reader() {
        if (cacheEmoji.containsKey("emoji")) {
            return cacheEmoji.get("emoji");
        } else {
            String result = "";
            try {
                File file = new File("E:\\test\\src\\test\\java\\com\\example\\demo\\1.json");
                InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8");
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    result += lineTxt;
                }
                read.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

            cacheEmoji.put("emoji", JSON.parseArray(result));
            return JSON.parseArray(result);
        }
    }
    @Nullable
    public static String  testNull(final Integer id){
        System.out.println(Character.digit('A', 16));
        return "";
    }

    public static void main(String[] args) {
        System.out.println(Integer.parseInt("Tom", 36));
        System.out.println(Integer.toString(38470,36));

    }
}
